<template>
  <xui-center-popup ref="popupRef" closeable @close="closeAd">
    <view class="ad" v-if="info" @click="$to(info.windowUrl)">
      <image class="ad-img" mode="widthFix" :src="info.windowImg"/>
    </view>
  </xui-center-popup>
</template>

<script>
import { ref } from 'vue'
import { getFloor } from '@/api/goods'
import { format } from '@/utils/time'

export default {
  name: 'VipQrcode',
  setup () {
    const popupRef = ref()
    const setCurrentDate = format(Date.now(), 'YYYYMMDD')
    const open = async () => {
      await getInfo()
      if (info.value.windowImg) {
        uni.setStorage({ key: 'adCurrentDate', data: setCurrentDate })
        popupRef.value.open()
      }
    }
    const close = () => popupRef.value.close()

    const info = ref()
    const getInfo = async () => {
      const res = await getFloor()
      info.value = res
    }
    const closeAd = () => {
      console.log('close')
    }
    return {
      closeAd,
      popupRef,
      open,
      close,
      info
    }
  }
}
</script>

<style lang="scss" scoped>
.ad {
  width: 600rpx;
  height: 846rpx;
  border-radius: 16rpx;
  text-align: center;
}
.ad-img {
  width: 568rpx;
}
</style>
